
//
//  HDPictureViewCell.swift
//  HDSwfitWeibo
//
//  Created by wty on 16/4/14.
//  Copyright © 2016年 wty. All rights reserved.
//

import UIKit

class HDPictureViewCell: UICollectionViewCell {
    //MARK -初始化方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //添加子控件  添加约束
    private func prepareUI(){
        //设置图片的模型
        imageView.contentMode = UIViewContentMode.ScaleAspectFill
        imageView.clipsToBounds = true
        contentView.addSubview(imageView)
        imageView.backgroundColor = UIColor.randomColor()
        imageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(contentView)
        }
        
    }
    //属性观察期来给子控件赋值
    var imageURL: NSURL? {
        didSet{
            
            imageView.sd_setImageWithURL(imageURL, placeholderImage: nil) { (image, error, _, _) -> Void in
                if  error != nil {
                    return
                }
              image.hd_AsyncDrawImage(nil, drawFinish: { (image) -> () in
                self.imageView.image = image
              })
             }
        }
    }
    
    //MARK -懒加载控件  
    lazy var  imageView:UIImageView = UIImageView()
    
}
